﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
	String basePath = "/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <base href="/">

    <!-- jsp文件头和头部 -->
    <%@ include file="../index/top.jsp" %>
    <script type="text/javascript" src="static/ace/js/jquery.js"></script>
    <!-- 上传图片插件 -->
    <link href="plugins/uploadify/uploadify.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="plugins/uploadify/swfobject.js"></script>
    <script type="text/javascript" src="plugins/uploadify/jquery.uploadify.v2.1.4.min.js"></script>
    <!-- 上传图片插件 -->
    <script type="text/javascript">
        var jsessionid = "<%=session.getId()%>";  //勿删，uploadify兼容火狐用到
    </script>
</head>
<body class="no-skin">

<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <div class="hr hr-18 dotted hr-double"></div>
                <div class="row">
                    <div class="col-xs-12">
                        <div style="width:600px;padding-left: 5px; display:table;">
                            <div class="dib" style="width:285px;float: left;">
                                <table id="table_report" class="table table-striped table-bordered table-hover">
                                    <tr>
                                        <td style="width: 85px; text-align: right; padding-top: 10px;">基地:</td>
                                        <td><select name="base_id" id="base_id" data-placeholder="选择基地"
                                                    style="vertical-align: top;width: 98%;">
                                            <option value="0">请选择</option>
                                            <c:forEach var="co" varStatus="i" items="${baseList}">
                                                <option value="${co.id }">${co.name}</option>
                                            </c:forEach>
                                        </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td style="width: 85px; text-align: right; padding-top: 10px;">商品:</td>
                                        <td><select name="goodsId" id="goodsId" data-placeholder="选择商品"
                                                    style="vertical-align: top;width: 98%;">
                                            <option value="0">请选择</option>
                                            <c:forEach var="co" varStatus="i" items="${goodsList}">
                                                <option value="${co.id }">${co.title}</option>
                                            </c:forEach>
                                        </select>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td
                                                style="width: 85px; text-align: right; padding-top: 13px;">期数:
                                        </td>
                                        <td colspan="1"><input type="text" name="time"
                                                               id="time" value="${goods.time }"
                                                               maxlength="32" placeholder="这里输入商品期次" title="商品期次"
                                                               style="width: 98%;"/></td>
                                    </tr>
                                    <tr>
                                        <td colspan="3" style="text-align: center;">
                                            <botton class="btn">生成二维码</botton>
                                        </td>
                                    </tr>

                                </table>
                            </div><!--/span-->
                            <div style="width:285px;float: right;">
                                <div class="widget-box" style="margin-top:0">
                                    <div class="widget-header widget-header-flat widget-header-small">
                                        <h5>
                                            生成二维码
                                        </h5>
                                        <div class="widget-toolbar no-border">
                                        </div>
                                    </div>
                                    <div class="widget-body">
                                        <div class="widget-main">
                                            <img id="encoderImgId" cache="false"
                                                 src="<%=basePath%>static/images/default.png" width="261px"
                                                 height="261px;"/>
                                        </div><!--/widget-main-->
                                    </div><!--/widget-body-->
                                </div><!--/widget-box-->
                            </div><!--/span-->
                        </div>
                    </div>
                    <div class="step-content row-fluid position-relative">
                        <input type="hidden" value="no" id="hasTp1"/>
                    </div>

                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </div>
        <!-- /.page-content -->
    </div>
</div>
<!-- /.main-content -->
<!-- 返回顶部 -->
<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
    <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
</a>
</div>
<!-- /.main-container -->

<!-- basic scripts -->
<!-- 页面底部js¨ -->
<%@ include file="../index/foot.jsp" %>
<!-- ace scripts -->
<script src="static/ace/js/ace/ace.js"></script>
<!--提示框-->
<script type="text/javascript" src="static/js/jquery.tips.js"></script>
<!--引入属于此页面的js -->
<script type="text/javascript" src="static/js/myjs/readTwoD.js"></script>
<script type="text/javascript">
    $(top.hangge());
    var locat = (window.location + '').split('/');
    $(function () {
        if ('tool' == locat[3]) {
            locat = locat[0] + '//' + locat[2];
        } else {
            locat = locat[0] + '//' + locat[2] + '/' + locat[3];
        }
        ;
    });
    $(".btn").on("click", function () {
        var time = $("#time").val();
        var base_id = $("#base_id").val();
        var goodsId = $("#goodsId").val();
        if (base_id == "0") {
            $("#base_id").tips({
                side: 3,
                msg: '请选择基地',
                bg: '#AE81FF',
                time: 2
            });
            $("#base_id").focus();
            return false;
        }
        if (goodsId == "0") {
            $("#goodsId").tips({
                side: 3,
                msg: '请选择商品',
                bg: '#AE81FF',
                time: 2
            });
            $("#goodsId").focus();
            return false;
        }
        if (time == "") {
            $("#time").tips({
                side: 3,
                msg: '请输入期次',
                bg: '#AE81FF',
                time: 2
            });
            $("#time").focus();
            return false;
        }

        $.ajax({
            type: "POST",
            url: '<%=basePath%>retrospect/createTwoDimensionCode.do',
            data: {'time': time, 'base_id': base_id, 'goodsId': goodsId},
            dataType: 'json',
            cache: false,
            success: function (data) {
                if ("success" == data.result) {
                    $(".btn").tips({
                        side: 1,
                        msg: '生成成功',
                        bg: '#75C117',
                        time: 3
                    });
                    $("#encoderImgId").attr("src", data.encoderImgId);
                } else {
                    $(".btn").tips({
                        side: 1,
                        msg: '生成失败',
                        bg: '#75C117',
                        time: 3
                    });
                    $("#encoderImgId").attr("src", "http://fruit-picture.oss-cn-beijing.aliyuncs.com/fruit/retrospect/default.png");
                }
            }
        });

    })
</script>
</body>
</html>